Imports Microsoft.VisualBasic
Imports System.Collections.Generic
Imports Security.Business
Imports Security.Entities

Public Class ECGPage
    Inherits System.Web.UI.Page

    Protected Sub HandleError(ByVal ex As Exception)
        If ex.GetType().BaseType.IsAssignableFrom(GetType(Common.Errors.ECGError)) Then
            Context.Items("ECGERROR") = ex
        Else
            Server.Transfer("~/Error.aspx")
        End If
    End Sub

    Protected Sub CheckRole(ByVal roleName As String)
        Try
            AuthorizationService.CheckRole(roleName)
        Catch ex As Common.Errors.UnauthorizedError
            Response.Redirect("~/Denied.aspx")
        Catch ex As Common.Errors.NotLoggedInError
            Response.Redirect("~/FrontEnd/Login.aspx")
        End Try
    End Sub

    Protected Function HasRole(ByVal roleName As String) As Boolean
        Try
            AuthorizationService.CheckRole(roleName)
        Catch ex As Common.Errors.UnauthorizedError
            Return False
        Catch ex As Common.Errors.NotLoggedInError
            Response.Redirect("~/FrontEnd/Login.aspx")
        End Try

        Return True
    End Function
End Class
